/*----------------空气质量分析页面的单独js代码部分start------------------*/
/*请求地址全局变量*/
// var RequestUrl = '.';
var RequestUrl = 'http://58.213.141.220:8989/njhbindex';
//var RequestUrl = 'http://127.0.01:8020/njhb_new';

/*建立缓存*/
var DataCachesEnable = true;//缓存总开关
var DataCacheValidity = 1000*1800;//30分钟有效期
var DataCaches=[];
//缓存重置
function cacheReset(){
	DataCaches['aqiitemsyear']=[];//每月污染物浓度比例图一
	DataCaches['aqiitemsyear']['year']=[];
	DataCaches['aqiitemsyear']['data']=[];
	
	DataCaches['aqiitemsday']=[];//每月污染物浓度比例图一
	DataCaches['aqiitemsday']['month']=[];
	DataCaches['aqiitemsday']['data']=[];
	
	DataCaches['aqiitems']=[];//每月污染物浓度比例图一指标切换
	DataCaches['aqiitems']['month']=[];
	DataCaches['aqiitems']['data']=[];
	
	DataCaches['aqidays']=[];//空气质量天数比例
	
	DataCaches['aqihours']=[];//同一时间段空气质量
	DataCaches['aqihours']['month']=[];
	DataCaches['aqihours']['data']=[];
	
	DataCaches['gypf']=[];//工业排放量
	DataCaches['aqims']=[];//工业排放aqi指标
}
cacheReset();
//缓存到期更新
setInterval(function(){
	if(DataCachesEnable){
		cacheReset();
	}
}, DataCacheValidity);

//同一时间段chart
var tysjd_chart;
//均线颜色
var avgColor = {aqi:'#01b3d9',pm25:'#e16f6e',pm10:'#688ff4',so2:'#23ae39',no2:'#e4b503',co:'#00E3D8',o3:'#FE9A01'};
var wr_month_html, thisMonth = (new Date()).pattern("M")-1, thisYear = (new Date()).pattern("yyyy");
var today_num = (new Date()).pattern("d");
// if(thisMonth==2){
// 	if(today_num>=14){
// 		thisMonth++
// 	}
// }else{
// 	if(today_num>=15){
// 		thisMonth++
// 	}
// }
if(thisMonth==0){
	thisYear-=1;
	thisMonth=12;
}
//每月污染物浓度比例-生成下拉菜单
var tmphl='',h2015='';
for(var i=1;i<=12;i++){
  	h2015+='<option value="'+(thisYear-1)+'-'+appendZeroleft(i)+'">'+(thisYear-1)+'年'+i+'月</option>';
}
for(var i=1;i<=thisMonth;i++){
	var selected = '';
	if(i==thisMonth){
		selected = 'selected';
	}
  	tmphl+='<option value="'+thisYear+'-'+appendZeroleft(i)+'" '+selected+'>'+thisYear+'年'+i+'月</option>';
}
$('.everymonth-select').html(h2015+tmphl);
tmphl='';
for(var i=2014;i<=thisYear;i++){
	var selected = '';
	if(i==thisYear){
		selected = 'selected';
	}
  	tmphl+='<option value="'+i+'" '+selected+'>'+i+'年</option>';
}
$('#everyyear-select').html(tmphl);

//初始化饼图一默认当月
set_wrchat_data_byyear(RequestUrl,thisYear);
set_wrchat_data_bymonth(RequestUrl,thisYear+'-'+appendZeroleft(thisMonth));
//初始化饼图二默认pm2.5//=>aqi
refreshChrat(RequestUrl,'wrchat-zhibiao',thisYear+'-'+appendZeroleft(thisMonth),'aqi');
//月份切换
$('#everyyear-select').change(function(){
	var v = $(this).val();
	if(thisYear!=v){
		thisYear=v;
		set_wrchat_data_byyear(RequestUrl,thisYear);
	}
})
$('#everymonth-select-1').change(function(){
	var v = $(this).val();
	set_wrchat_data_bymonth(RequestUrl,v);//每月污染物浓度比例图一
	// var zb = $('.zhibiao-item.active').attr('dn');
	// refreshChrat(RequestUrl,'wrchat-zhibiao',v,zb);//每月污染物浓度比例图二
	$('#everymonth-select-1').val(v);
})
$('#everymonth-select-2').change(function(){
	var v = $(this).val();
	// set_wrchat_data_bymonth(RequestUrl,v);//每月污染物浓度比例图一
	var zb = $('.zhibiao-item.active').attr('dn');
	refreshChrat(RequestUrl,'wrchat-zhibiao',v,zb);//每月污染物浓度比例图二
	$('#everymonth-select-2').val(v);
})
//指标切换
$('.bing .zhibiao-item').on('click',function(){
	$(this).addClass('active').siblings('.zhibiao-item').removeClass('active');
	//月份
	var m = $('.everymonth-select').val();
	//指标
	var zb = $(this).attr('dn');
	//刷新图表
	refreshChrat(RequestUrl,'wrchat-zhibiao',m,zb);
})

//堆叠柱状图
make_wrchat_column(RequestUrl,'wrchat-airquality');//空气质量天数比例

/*生成下拉菜单*/
tmphl='';
for(var i=1;i<=thisMonth;i++){
	var selected = '';
	if(i==thisMonth){
		selected = 'selected';
	}
  	tmphl+='<option value="'+i+'" '+selected+'>'+thisYear+'年'+i+'月</option>';
}
$('#onetime-select').html(tmphl);

//同一时间段空气质量/折线图
make_wrchat_line(RequestUrl,'wrchat-onetimeair',thisYear+'-'+appendZeroleft(thisMonth));
$('#onetime-select').val(thisMonth);
//折线图月份切换
$('#onetime-select').change(function(){
	var zb = $('.zhe .zhibiao-item.active').attr('dn');
	var min = $('.zhe .zhibiao-item.active').attr('min');
	make_wrchat_line(RequestUrl,'wrchat-onetimeair',thisYear+'-'+ appendZeroleft($(this).val()),zb,min);
})
//折线图指标切换
$('.zhe .zhibiao-item').on('click',function(){
	if($(this).hasClass('active')){
		return false;
	}
	var p = $(this).siblings('.active');
	var pi = p.attr('ix');
	var pavgid = p.attr('dn');
	tysjd_chart.series[pi].hide();
	
	$(this).addClass('active').siblings().removeClass('active');
	//月份
	var m = $('#onetime-select').val();
	//指标
	var zb = $(this).attr('dn');
	//index
	var ix = $(this).attr('ix');
	//avg
	var avg = $(this).attr('avg');
	//min
	var minz = $(this).attr('min');
	//刷新图表
	if($(this).hasClass('active')){
		make_wrchat_line(RequestUrl,'wrchat-onetimeair',thisYear+'-'+ appendZeroleft(m),zb,minz);
//		tysjd_chart.series[ix].show();
//		tysjd_chart.yAxis[0].removePlotLine('PlotLine-'+pavgid);
//		tysjd_chart.yAxis[0].addPlotLine({
//			color: avgColor[zb],
//      	dashStyle:'ShortDash',
//      	width: 1,
//      	value: avg,
//      	id:'PlotLine-'+zb
//		})
//		tysjd_chart.yAxis[0].update({min:minz});
	}
})

//工业排放量/条形图
make_wrchat_columngroup(RequestUrl,'wrchat-factoryout');

/*----------------空气质量分析页面的单独js代码部分end------------------*/